package com.atguigu.gmall.item.rpc.controller;


import com.atguigu.gmall.common.constant.RedisConstant;
import com.atguigu.gmall.item.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RequestMapping("/api/inner")
@RestController
public class ItemController {


    ///sku/detail/{skuId}

    @Autowired
    ItemService itemService;

    @GetMapping("/sku/detail/{skuId}")
    public  Map<String,Object> itemDetail(@PathVariable("skuId") Long skuId) throws Exception {

        //1、查询sku的详情数据
       Map<String,Object> detail = itemService.getItemDetail(skuId);

       //修改完Sku? 调用 cacheService.deleteDataFromCache(RedisConstant.SKU_DETAIL+skuId);

        //热度更新到es中去
        itemService.incrHotScore(skuId);

        return detail;
    }
}
